package com.qf.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.sql.DataSource;

/**
 * @ClassName SpringConfig
 * @Description TODO
 * @Author 86181
 * @Date 2022/9/2 14:20
 * @Version 1.0
 **/
@Configuration
@ComponentScan(basePackages = "com.qf")
@Import({JdbcConfig.class})
@EnableTransactionManagement
public class SpringConfig {
        @Autowired
    private DataSource dataSource;

        @Bean("jdbcTemplate")
    public JdbcTemplate jdbcTemplate(){
            return new JdbcTemplate(dataSource);
        }
        @Bean("manager")
    public DataSourceTransactionManager dataSourceTransactionManager(){
            DataSourceTransactionManager manager = new DataSourceTransactionManager();
            manager.setDataSource(dataSource);
            return manager;
        }

}
